//引入api
import{
    requestDetailList
} from "@/api"

//detail模块的配置
const state = {
    detailList: {}
}

const mutations  = {
    //1.修改detailList的mutations
    SET_DETAILLIST_STATE(state , value){
        state.detailList = value
    }
}

const actions = {
    //1.请求单个商品详情
    async getDetailList({commit} , skuId){
        const result = await requestDetailList(skuId)
        commit("SET_DETAILLIST_STATE" , result)
    }
}

const getters = {
    skuInfo(state){
        return state.detailList.skuInfo || {}
    },
    categoryView(state){
        return state.detailList.categoryView || {}
    },
    spuSaleAttrList(state){
        return state.detailList.spuSaleAttrList || []
    },
}

export default {
    //开启命名空间
    namespaced: true,
    state,
    mutations,
    actions,
    getters,
}